cmake_minimum_required(VERSION 3.13)
project(sparrow VERSION 1.0.0 LANGUAGES C CXX)

# This project can use C11, but will gracefully decay down to C89.
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED OFF)
set(CMAKE_C_EXTENSIONS OFF)

# This project requires C++11.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

option(BUILD_SHARED_LIBRARY "Build sparrow shared library" ON)

include(TestBigEndian)
test_big_endian(IsBigEndian)

aux_source_directory(${PROJECT_SOURCE_DIR}/src/base64 SP_BASE64_SRC)
aux_source_directory(${PROJECT_SOURCE_DIR}/src/date SP_DATE_SRC)
aux_source_directory(${PROJECT_SOURCE_DIR}/src/hash SP_HASH_SRC)
aux_source_directory(${PROJECT_SOURCE_DIR}/src/os SP_OS_SRC)
aux_source_directory(${PROJECT_SOURCE_DIR}/src/json SP_JSON_SRC)
aux_source_directory(${PROJECT_SOURCE_DIR}/src/sha SP_SHA_SRC)
aux_source_directory(${PROJECT_SOURCE_DIR}/src/strings SP_STRINGS_SRC)

if(BUILD_SHARED_LIBRARY)
    add_library(sparrow SHARED "")
else()
    add_library(sparrow STATIC "")
endif()

target_sources(sparrow
PRIVATE
    ${SP_BASE64_SRC}
    ${SP_DATE_SRC}
    ${SP_HASH_SRC}
    ${SP_OS_SRC}
    ${SP_JSON_SRC}
    ${SP_SHA_SRC}
    ${SP_STRINGS_SRC}
)

target_include_directories(sparrow
PRIVATE
    ${PROJECT_SOURCE_DIR}/include
    ${PROJECT_SOURCE_DIR}
)

if(${IsBigEndian})
    target_compile_definitions(sparrow
    PRIVATE
        WORDS_BIGENDIAN=1
    )
    message(STATUS "System is big endian")
else()
    message(STATUS "System is little endian")
endif()

if(BUILD_SHARED_LIBRARY)
    target_compile_definitions(sparrow
    PRIVATE
        SPARROW_SHARED_LIBRARY=1
    )
endif(BUILD_SHARED_LIBRARY)

target_compile_definitions(sparrow
PRIVATE
    SPARROW_COMPILE_LIBRARY=1
)

target_compile_options(sparrow
PRIVATE
    -Wall
    -g
)
